/*
 * Connect.java - Universal connector to different MySQL databases.
 *
 * Copyright (c) 2007 Computer-Aided Integrated Systems Laboratory, 
 * St. Petersburg Institute for Informatics and Automation RAS http://cais.lisa.iias.spb.su
 */

package dbcontext;

import java.sql.*;

/** Universal connector to different MySQL databases.
 */
public class Connect {
    
    /** context database */
    public final static String CONTEXT_DB   = "192.168.0.101:3306/context?useUnicode=true&characterEncoding=UTF-8";   // latin1
    //public final static String CONTEXT_DB   = "localhost/context?useUnicode=true&characterEncoding=UTF-8";   // latin1
    public final static String CONTEXT_USER = "michael";
    public final static String CONTEXT_PASS = "12345";
    
    public static java.sql.Connection getDBConnection(String isDatabaseName, String isLogin, String isPassword) {
        java.sql.Connection db_conn = null;
        try{
            db_conn = getConnection( isDatabaseName, isLogin, isPassword );
        } catch ( Exception e ) {
            e.printStackTrace( );
        }
        return db_conn;
    }
    
    private static Connection getConnection( String isDatabaseName, String isLogin, String isPassword ) throws Exception 
    {
        Driver d = (Driver)Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
        Connection c = DriverManager.getConnection( "jdbc:mysql://" + isDatabaseName, isLogin, isPassword ); // &autoReconnect=true&useUnbufferedInput=false
        return c;
    }
	
}
